package com.hikvision.rpq.sblearn.exception;

import com.hikvision.rpq.sblearn.common.ResponseInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一异常处理
 * @author renpeiqian
 * @date 2021/9/7 15:12
 * @since
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {



    /**
     * 其他没有处理的错误
     *
     * @param e
     * @return
     */
    @ExceptionHandler
    public ResponseInfo handle(BusinessException exception) {
        //errorCode处理
        log.error(exception.getCode(), exception);
        return new ResponseInfo(exception.getCode(), exception.getMessage());
    }


    @ExceptionHandler(Exception.class)
    public ResponseInfo  handlerException(Exception e){
        String code= "0x1001";
        log.error(code, e);
        return new ResponseInfo<>(code,e.getMessage());
    }

}